package com.zbkj.crmeb.front.controller;


import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.common.CommonPage;
import com.crmeb.core.common.CommonResult;
import com.common.PageParamRequest;
import com.zbkj.crmeb.enums.BannerTypeEnum;
import com.zbkj.crmeb.front.request.ProductRequest;
import com.zbkj.crmeb.front.service.ProductService;
import com.zbkj.crmeb.store.model.StoreBanner;
import com.zbkj.crmeb.store.response.StoreProductResponse;
import com.zbkj.crmeb.store.service.StoreBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 专区 轮播图
 */
@Slf4j
@RestController("ZoneBannerController")
@RequestMapping("api/front/")
@Api(tags = "专区轮播图")
public class ZoneBannerController {

    @Autowired
    private StoreBannerService storeBannerService;
    @Autowired
    private ProductService productService;

    /**
     * banner列表
     * @author Mr.Zhang
     * @since 2020-06-01
     */
    @ApiOperation(value = "banner列表")
    @RequestMapping(value = "/banner/list", method = RequestMethod.GET)
    public CommonResult<List<StoreBanner>> bannerList(@Validated StoreBanner storeBanner){
        return CommonResult.success(storeBannerService.getList(storeBanner));
    }

    /**
     * banner关联专区下面的商品列表
     * @author Mr.Zhang
     * @since 2020-06-01
     */
    @ApiOperation(value = "banner列表")
    @RequestMapping(value = "/banner/zone/goodsList", method = RequestMethod.GET)
    public CommonResult<CommonPage<StoreProductResponse>> getStoreZoneGoodsList(
            @Validated ProductRequest request, @Validated PageParamRequest pageParamRequest){
        if(ObjectUtils.isEmpty(request.getBannerId())){
            return CommonResult.failed("请传入bannerId");
        }
        StoreBanner storeBanner = storeBannerService.getStoreBanner(request.getBannerId());
        if(null == storeBanner){
            return CommonResult.failed("轮播图已经被删除");
        }
        if(BannerTypeEnum.ZONE.getType() != storeBanner.getType()){
            return CommonResult.failed("轮播图找不到专区");
        }
        request.setZoneId(storeBanner.getTypeId());
        return CommonResult.success(productService.selectZoneProductList(request,pageParamRequest));
    }
}



